﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraControl : MonoBehaviour
{
    public static CameraControl Instance;
    public Transform mTran;
    public Transform target;
    public Vector3 offset;
    public Vector3 min;
    public Vector3 max;
    public float smoothing = 5f;

    void Start()
    {
        Instance = this;
        mTran = transform;
    }

    public void SetTarget(Transform tar)
    {
        target = tar;
    }

    void LateUpdate()
    {
        if (target != null)
        {
            Vector3 goalPoint = target.position + offset;
            goalPoint.x = Mathf.Clamp(goalPoint.x, min.x, max.x);
            goalPoint.y = Mathf.Clamp(goalPoint.y, min.y, max.y);
            goalPoint.z = Mathf.Clamp(goalPoint.z, min.z, max.z);
            transform.position = Vector3.Lerp(transform.position, goalPoint, smoothing * Time.deltaTime);
        }
    }
}
